package com.gis507.mapreduce.AISBean;

import com.gis507.test.AISDataSort.AISDataBean;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AisClassifyBean implements Writable, DBWritable,Comparable<AisClassifyBean> {

    private String mmsi;
    private String shipType;
    //3、到达港口
    private String nacStatusCN;
    private double length;
    private double width;
    private double draught;
    private double heading;
    private double course;
    private double speed;
    private String dest;
    private long unixTime;
    private double lon_d;
    private double lat_d;
    //12、海域
    private int seaRange;
    //
    private double tonnage;

    public AisClassifyBean(String mmsi, String shipType, String nacStatusCN, double length, double width, double draught, double heading, double course, double speed, String dest, long unixTime, double lon_d, double lat_d, int seaRange, double tonnage) {
        this.mmsi = mmsi;
        this.shipType = shipType;
        this.nacStatusCN = nacStatusCN;
        this.length = length;
        this.width = width;
        this.draught = draught;
        this.heading = heading;
        this.course = course;
        this.speed = speed;
        this.dest = dest;
        this.unixTime = unixTime;
        this.lon_d = lon_d;
        this.lat_d = lat_d;
        this.seaRange = seaRange;
        this.tonnage = tonnage;
    }

    public AisClassifyBean(String mmsi, String shipType, String nacStatusCN, double draught, double heading, double course, double speed, String dest, long unixTime, double lon_d, double lat_d, int seaRange) {
        this.mmsi = mmsi;
        this.shipType = shipType;
        this.nacStatusCN = nacStatusCN;
        this.draught = draught;
        this.heading = heading;
        this.course = course;
        this.speed = speed;
        this.dest = dest;
        this.unixTime = unixTime;
        this.lon_d = lon_d;
        this.lat_d = lat_d;
        this.seaRange = seaRange;
    }


    public AisClassifyBean() {
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getTonnge() {
        return tonnage;
    }

    public void setTonnge(double tonnge) {
        this.tonnage = tonnge;
    }

    public String getMmsi() {
        return mmsi;
    }

    public void setMmsi(String mmsi) {
        this.mmsi = mmsi;
    }

    public String getShipType() {
        return shipType;
    }

    public void setShipType(String shipType) {
        this.shipType = shipType;
    }

    public String getNacStatusCN() {
        return nacStatusCN;
    }

    public void setNacStatusCN(String nacStatusCN) {
        this.nacStatusCN = nacStatusCN;
    }

    public double getDraught() {
        return draught;
    }

    public void setDraught(double draught) {
        this.draught = draught;
    }

    public double getHeading() {
        return heading;
    }

    public void setHeading(double heading) {
        this.heading = heading;
    }

    public double getCourse() {
        return course;
    }

    public void setCourse(double course) {
        this.course = course;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public String getDest() {
        return dest;
    }

    public void setDest(String dest) {
        this.dest = dest;
    }

    public long getUnixTime() {
        return unixTime;
    }

    public void setUnixTime(long unixTime) {
        this.unixTime = unixTime;
    }

    public double getLon_d() {
        return lon_d;
    }

    public void setLon_d(double lon_d) {
        this.lon_d = lon_d;
    }

    public double getLat_d() {
        return lat_d;
    }

    public void setLat_d(double lat_d) {
        this.lat_d = lat_d;
    }

    public int getSeaRange() {
        return seaRange;
    }

    public void setSeaRange(int seaRange) {
        this.seaRange = seaRange;
    }

    @Override
    public String toString() {
        return mmsi + "," +
                shipType + ","+
                nacStatusCN + "," +
                length + "," +
                width + "," +
                draught + "," +
                heading +
                "," + course +
                "," + speed +
                "," + dest +
                "," + unixTime +
                "," + lon_d +
                "," + lat_d +
                "," + seaRange +
                "," + tonnage;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {

        //String mmsi, String shipType, String nacStatusCN, double draught,
        // double heading, double course, double speed, String dest,
        // long unixTime, double lon_d, double lat_d, int seaRange
        dataOutput.writeUTF(mmsi);
        dataOutput.writeUTF(shipType);
        dataOutput.writeUTF(nacStatusCN);
        dataOutput.writeDouble(length);
        dataOutput.writeDouble(width);
        dataOutput.writeDouble(draught);
        dataOutput.writeDouble(heading);
        dataOutput.writeDouble(course);
        dataOutput.writeDouble(speed);
        dataOutput.writeUTF(dest);
        dataOutput.writeLong(unixTime);
        dataOutput.writeDouble(lon_d);
        dataOutput.writeDouble(lat_d);
        dataOutput.writeInt(seaRange);
        dataOutput.writeDouble(tonnage);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {

        this.mmsi = dataInput.readUTF();
        this.shipType = dataInput.readUTF();
        this.nacStatusCN = dataInput.readUTF();
        this.length = dataInput.readDouble();
        this.width = dataInput.readDouble();
        this.draught = dataInput.readDouble();
        this.heading = dataInput.readDouble();
        this.course = dataInput.readDouble();
        this.speed = dataInput.readDouble();
        this.dest = dataInput.readUTF();
        this.unixTime = dataInput.readLong();
        this.lon_d = dataInput.readDouble();
        this.lat_d = dataInput.readDouble();
        this.seaRange = dataInput.readInt();
        this.tonnage = dataInput.readDouble();

    }



    //String mmsi, String shipType, String nacStatusCN, double draught,
    // double heading, double course, double speed, String dest,
    // long unixTime, double lon_d, double lat_d, int seaRange
    @Override
    public void write(PreparedStatement statement) throws SQLException {
        statement.setString(1,this.mmsi);
        statement.setString(2,this.shipType);
        statement.setString(3,this.nacStatusCN);
        statement.setDouble(4,this.length);
        statement.setDouble(5,this.width);
        statement.setDouble(6,this.draught);
        statement.setDouble(7,this.heading);
        statement.setDouble(8,this.course);
        statement.setDouble(9,this.speed);
        statement.setString(10,this.dest);
        statement.setLong(11,this.unixTime);
        statement.setDouble(12,this.lon_d);
        statement.setDouble(13,this.lat_d);
        statement.setInt(14,this.seaRange);
        statement.setDouble(15,this.tonnage);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {

        this.mmsi = resultSet.getString(1);
        this.shipType = resultSet.getString(2);
        this.nacStatusCN = resultSet.getString(3);
        this.length = resultSet.getDouble(4);
        this.width = resultSet.getDouble(5);
        this.draught = resultSet.getDouble(6);
        this.heading = resultSet.getDouble(7);
        this.course = resultSet.getDouble(8);
        this.speed = resultSet.getDouble(9);
        this.dest = resultSet.getString(10);
        this.unixTime = resultSet.getLong(11);
        this.lon_d = resultSet.getDouble(12);
        this.lat_d = resultSet.getDouble(13);
        this.seaRange = resultSet.getInt(14 );
        this.tonnage = resultSet.getDouble(15);
    }

    @Override
    public int compareTo(AisClassifyBean o) {

        long l = this.getUnixTime() - o.getUnixTime();

        return (int) l;
    }
}
